package com.dwy2002.order.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.dwy2002.order.mapper.OrderRoomMapper;
import com.dwy2002.order.service.IOrderRoomService;
import com.dwy2002.pojo.dto.rooms.ReserveRoomDTO;
import com.dwy2002.pojo.po.order.OrderRoom;
import com.dwy2002.pojo.po.rooms.Rooms;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import static com.dwy2002.common.utils.Utils.validateIdNotEmpty;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/06
 */
@Service
@RequiredArgsConstructor
public class OrderRoomServiceImpl extends ServiceImpl<OrderRoomMapper, OrderRoom> implements IOrderRoomService {
    /**
     * 保存订单商品类
     *
     * @param orderId 订单ID
     * @param dto     订单包间类DTO
     * @author 杜伟毅
     * @since 2025/3/10 0010 22:20
     */
    @Override
    public void saveOrderRoom(String orderId, ReserveRoomDTO dto) {
        validateIdNotEmpty(orderId, "saveOrderRoom");
        OrderRoom orderRoom = BeanUtil.copyProperties(dto, OrderRoom.class);
        orderRoom.setOrderId(orderId);
        save(orderRoom);
    }

    /**
     * 查询包间信息
     *
     * @param orderId 订单ID
     * @return 返回包间类
     * @author 杜伟毅
     * @since 2025/3/12 0012 19:45
     */
    @Override
    public Rooms getRoomsByOrderId(String orderId) {
        validateIdNotEmpty(orderId, "getRoomsByOrderId");
        LambdaQueryWrapper<OrderRoom> lqw = new LambdaQueryWrapper<>();
        lqw.eq(OrderRoom::getOrderId, orderId);
        return Db.getById(getOne(lqw).getRoomId(), Rooms.class);
    }

    /**
     * 根据订单id删除查询信息
     *
     * @param orderId 订单ID
     * @author 杜伟毅
     * @since 2025/3/12 0012 17:04
     */
    @Override
    public void deleteOrderRoom(String orderId) {
        validateIdNotEmpty(orderId, "deleteOrderRoom");
        LambdaQueryWrapper<OrderRoom> lqw = new LambdaQueryWrapper<>();
        lqw.eq(OrderRoom::getOrderId, orderId);
        remove(lqw);
    }


}
